<template>
	<div>
		<el-dialog title="药物不良反应自定义" :visible.sync="dialogVisibleXiangHu" width="60%" :before-close="handleClose">
			<el-card>
				<el-row :gutter="15">
					<el-form label-width="80px">
						<el-col :span="12" style="height:62px;">
							<el-form-item label="诊断名称">
								<el-input v-model="checkName"  :readonly="true"  size="mini" style="width:150px;"></el-input>
								<el-button type="primary" size="mini" @click="openSelect">选择</el-button>
								<el-button type="primary" size="mini">清除</el-button>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="审查级别">
								<el-select v-model="slCode" placeholder="请选择审查级别">
									<el-option
									  v-for="item in jsjbOptions"
									  :key="item.value"
									  :label="item.label"
									  :value="item.value">
									</el-option>
								</el-select>
							</el-form-item>	
						</el-col>
					</el-form>
				</el-row>
				<div class="clear">
					<el-button type="success" class="fr" @click="onSubmit">保存</el-button>
				</div>
			</el-card>
			<el-card style="margin-top:10px">
				<Graytable :tHead="tHead" :tData="tData"  @operateClick="operateClick"></Graytable>
				<pagination
					:total="query.total"
					:page.sync="query.page"
					:limit.sync="query.limit"
					@pagination="getList"/>
			</el-card>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisibleXiangHu = false">关 闭</el-button>
			</span>
		</el-dialog>
		<SelectDialog ref="selectDialog" ctype="不良反应" :dataObj="nowData" :checkId="checkId" @selectFun="selectFun"></SelectDialog>
	</div>
</template>

<script>
	import SelectDialog from "./selectDialog";
	export default {
		components: {
			SelectDialog
		},
		props:{
			dataObj:{
				required:true
			}
		},
		data () {
			return {
				query: {
				  total: 0,
				  page: 1,
				  limit: 10
				},
				slCode:"",//警示级别
				jsjbOptions:[
					{
					  value: '0',
					  label: '拦截'
					},
					{
					  value: '1',
					  label: '禁忌'
					},
					{
					  value: '2',
					  label: '不推荐'
					},
					{
					  value: '3',
					  label: '轻微'
					},
				],//警示级别options
				dialogVisibleXiangHu:false,
				tHead:[
					{
						label:"操作",
						operate:["删除"],
						align:"center",
						width:"50px"
					},
					{
						prop:"zddm",
						label:"疾病编码",
						
					},
					{
						prop:"zdmc",
						label:"疾病名称"
					},
					{
						prop:"slCode_txt",
						label:"警示级别"
					},
					{
						prop:"operUser",
						label:"操作人"
					},
				],
				tData:[],
				checkId:"",
				checkName:"",
				remark:"",
				nowData:{}
			}
		},
		watch:{
			dataObj(val){
				this.nowData=val;
				this.resetTData(true);
			}
		},
		methods:{
			selectFun(id,name){
				this.checkName=name;
				this.checkId=id;
			},
			clearFun(){
				this.checkName="";
				this.checkId="";
			},
			openSelect () {
				this.$refs.selectDialog.show()
			},
			async getList () {
				let res=await this.$custom.listModuleSelected({
					moduleId:"8",
					drugUniqueCode:this.nowData.drugUniqueCode,
					page:this.query.page,
					pageSize:this.query.limit
				})
				this.tData=res.rows;
				this.query.total=res.total;
			},
			show(){
				this.dialogVisibleXiangHu = true;
			},
			async onSubmit () {
				if(!this.checkId){
					this.$message({
					  message: "请选择诊断名称",
					  type:'error',
					  duration:1000
					});
					return;
				}
				let res=await this.$custom.listModuleSave({
					moduleId:"8",
					drugUniqueCode:this.nowData.drugUniqueCode,
					disCode:this.checkId,
					slCode:this.slCode,
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			},
			resetTData(flag){
				this.checkId="";
				this.checkName="";
				this.slCode="0";
				this.remark="";
				this.query={
					total:0,
					page:1,
					limit:10
				}
				this.tData=[];
				this.getList();
				if(!flag){
					this.$emit("changeFun")
				}
			},
			handleClose () {
				this.dialogVisibleXiangHu = false;
			},
			operateClick(item,row){
				this.$confirm('确定删除通用自定义?', '提示', {
					confirmButtonText: '确定删除',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.delFun(row);
				}).catch(() => {
				});
			},
			async delFun(row){
				let res=await this.$custom.listModuleDel({
					drugUniqueCode:this.nowData.drugUniqueCode,
					id:row.id
				})
				this.$message({
				  message: res.msg,
				  type: res.code == 1?'success':'error',
				  duration:1500
				});
				this.resetTData();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.el-card {
		margin-left: 3px;
	}

	.SearchT {
		display: flex;
		justify-content: flex-end;
		height: 40px;
		align-items: center;
		background-color: #e6edf3;
		font-size: 14px;
	}

	.tableLable {
		flex: 1;
		text-align: left;
		margin-left: 15px;
		letter-spacing: 2px;
		font-size: 14px;
		color: #32a6f3;
		font-weight: bold;
	}

	/* .exportBtn {
  margin-right: 23px;
}
.BatchDeleBtn {
  margin-right: 15px;
} */
	.tableStyle {
		width: 100%;
		height: 100%;
	}

	.card-table {
		width: 100%;
		height: 75%;
	}

	.block {
		text-align: center;
		margin-top: 12px;
		margin-bottom: 12px;
	}

	.Btn {
		display: flex;
		flex: 1;
		flex-wrap: nowrap;
	}

	.dialogFirstRow>>>.el-input {
		width: 70px;
		margin-right: 10px;
	}

	.el-form-item.s_selectbox>>>.el-form-item__content {
		width: 80%;
	}
	/* .demo-form-inline>>>.el-form-item {
		margin-bottom: 0px;
	} */
</style>
